<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Routing example - OpenError</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" language="javascript" src="js/OpenError.js"></script>
<script type="text/javascript" language="javascript" src="js/data_params.js"></script>
<script type="text/javascript" language="javascript" src="js/DispObjects.js"></script>
<script type="text/javascript">
  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;
  var oe;

  function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var myOptions = {
      zoom: 15,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: new google.maps.LatLng(52.636,-1.1325)
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    directionsDisplay.setMap(map);
	
	// create a new openerror object for introducing controlled error
	oe = new OpenError();
	oe.setDataSet(ptsLei2);  // var created on dataset.js file
	oe.setStandardDeviation(90); //1609.344);
	oe.setDebug( false );
	oe.setCorrelated( false );
	
	// create a new display object for organizing map data
	disp = new DispObject("map", "g3");
	calcRoute();
  }
var resp;
  function calcRoute() {
  
	var points = disp.addPoints();
	disp.hidePoints();
    begin = new google.maps.LatLng(points[0].lat, points[0].lon);
    end = new google.maps.LatLng(points[1].lat, points[1].lon);
    //var selectedMode = document.getElementById("mode").value;
    var request = {
        origin: begin,
        destination: end,
        // Note that Javascript allows us to access the constant
        // using square brackets and a string value as its
        // "property."
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        //directionsDisplay.setDirections(response);
		resp = response;
		
		

			polylineOptions = {
					map: map,
					strokeColor: "#FF0000",
					strokeOpacity: 0.3,
					strokeWeight: 5,
					path: response.routes[0].overview_path,
			}
			new google.maps.Polyline(polylineOptions);

      }
    });
  }
</script>
</head>
<FONT FACE="Arial, Helvetica, Geneva">

<body style="margin:0px; padding:0px;" onload="initialize()">
<h2>Propagating Positional Uncertainty to Routing Applications</h2>
<p>This example demonstrates how OpenError can be used to propagate
uncertainty to the Google Maps routing application. Positional error (90 m = 1 sd)
is simulated for origin and destination points in central Leicester (UK);
These locations are submitted to the Routing API. The route is drawn
with a translucent red line. Press 'Add Route' to generate another point 
realization, calculate its route, and add it to the map. Small
differences in position can result in wildly different routes - this is 
error propagation!</p>
<div>
<b>Add Another Route: </b>
<input type="button" value="Route" onclick="calcRoute();" />
</div>
<div id="map_canvas" style="width:80%; height:80%"></div>
<p><a href='./index.html'><i>OpenError</i></a></p>
</body>
</html>
